﻿#ifndef ULOADINGDIALOG_H
#define ULOADINGDIALOG_H

#include "udialog.h"

#include <QIcon>
#include <QVariantAnimation>

class UTKWIDGET_EXPORT LoadingWidget : public QWidget
{
    Q_OBJECT
public:
    explicit LoadingWidget(QWidget* parent = nullptr);
    ~LoadingWidget() {}

    void setIconSize(const QSize &iconSize);

    void setIcon(const QIcon &icon);

    void start(int nTime);

    void stop();

protected:
    void paintEvent(QPaintEvent* event) override;

private:
    void initAnimation();

    QVariantAnimation m_variantAnimation;
    QSize m_iconSize = QSize();
    QIcon m_icon = QIcon();
    int m_angle = 0;
};

class ULabel;
class UTKWIDGET_EXPORT LoadingDialog : public UDialog
{
    Q_OBJECT
public:
    explicit LoadingDialog(QWidget* parent = nullptr);
    ~LoadingDialog() {}

    void setIconSize(const QSize &iconSize);

    void setIcon(const QIcon &icon);

    void start(int nTime);

    void stop();

    void setText(const QString &text);

    QString text();

private:
    void initUi();
    void initAnimation();

    LoadingWidget* m_loadingWidget = nullptr;
    ULabel* m_textLabel = nullptr;
};
#endif // ULOADINGDIALOG_H
